﻿using Fabrication.Tests.Mocks;
using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabrication.Tests
{
    [TestFixture]
    public class convention_rules
    {
        [Test]
        public void should_use_convention_if_no_rule_defined()
        {
            var provider = new MockValueProvider((x, count) => "Convention" + count);
            var scope = new FabricationScope();
            scope.RemoveAllNamedConventions();
            scope.SetConvention<string>(provider, "Value");

            var builtItem = scope.Setup<SinglePropertyClass<string>>()
                            .Generate();

            Assert.That(builtItem.Value, Is.EqualTo("Convention1"));
        }

        [Test]
        public void should_use_defined_rule_over_convention()
        {
            var provider = new MockValueProvider((x, count) => "Convention" + count);
            var scope = new FabricationScope();
            scope.RemoveAllNamedConventions();
            scope.SetConvention<string>(provider, "Value");

            var builtItem = scope.Setup<SinglePropertyClass<string>>()
                            .For(x => x.Value).Use("Custom")
                            .Generate();

            Assert.That(builtItem.Value, Is.EqualTo("Custom"));
        }

        [Test]
        public void should_ignore_case_when_matching_conventions()
        {
            var provider = new MockValueProvider((x, count) => "Convention" + count);
            var scope = new FabricationScope();
            scope.RemoveAllNamedConventions();
            scope.SetConvention<string>(provider, "vALuE");

            var builtItem = scope.Setup<SinglePropertyClass<string>>()
                            .Generate();

            Assert.That(builtItem.Value, Is.EqualTo("Convention1"));
        }

        [Test]
        public void should_use_default_if_convention_property_name_has_mismatched_type()
        {
            var provider = new MockValueProvider((x, count) => "Convention" + count);
            var scope = new FabricationScope();
            scope.RemoveAllNamedConventions();
            scope.SetConvention<string>(provider, "FirstName");

            var builtItem = scope.Setup<NumericNameClass>()
                            .Generate();

            Assert.That(builtItem.FirstName, Is.EqualTo(1));
        }
    }
}
